//
//  YZTableViewController.m
//  kuaiyi
//
//  Created by Liu on 16/5/4.
//
//
//Users/liu/Desktop/实战项目/kuaiyi/KUAIYI
#import "YZAttDocTableViewController.h"
#import "YZAttDoc.h"
#import "YZAttDocCell.h"
#import "YZAttDocInfoViewController.h"
#import <MJRefresh.h>
#import "MBProgressHUD+Liu.h"
@interface YZAttDocTableViewController ()

/**
 *  医生模型
 */
@property (nonatomic, strong)NSArray *attDoc;

/**
 *  titleView
 */
@property (nonatomic, strong)UILabel *titleView;
/**
 *  弹窗
 */


@end

@implementation YZAttDocTableViewController

- (void)viewDidLoad {
     [super viewDidLoad];

    //预估行高
    self.tableView.estimatedRowHeight = 89;
    //隐藏cell的那条分割线
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //设置下拉回调
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    //设置上拉回调
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadOldData)];
    //设置title
    self.navigationItem.titleView = self.titleView;
}


#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.attDoc.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    YZAttDocCell *cell = [YZAttDocCell attDocCell:tableView];
    cell.attDocArr= self.attDoc[indexPath.row];
    cell.DocConsultBlock = ^(){
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"医生关闭了咨询" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alert animated:YES completion:nil];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self dismissViewControllerAnimated:YES completion:nil];
        });
    
    };
    return cell;
}

#pragma mark - Table view delegate
/**
 *  点击每一行的时候跳转界面
 */
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        YZAttDocInfoViewController *VC = [[YZAttDocInfoViewController alloc]init];
    [self.navigationController pushViewController:VC animated:YES];

}


#pragma mark - 下拉刷新 上拉加载 方法
/**
 *  下拉刷新
 */
-(void)loadNewData {
    [self.tableView reloadData];
        [self.tableView.mj_header endRefreshing];
}
/**
 *  上拉刷新
 */
-(void)loadOldData {
    [self.tableView reloadData];
    [self.tableView.mj_footer endRefreshing];
}



#pragma mark - 懒加载
-(NSArray *)attDoc{
    if (_attDoc == nil) {
        _attDoc = [YZAttDoc AttDocArr];
    }
    return _attDoc;
}

-(UILabel *)titleView {
    if (_titleView == nil) {
        _titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
        [_titleView setTextColor:[UIColor whiteColor]];
        [_titleView setText:@"选择医生"];
    }
    return _titleView;
}



@end
